🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / core / data / src / commonMain / kotlin / org / meshtastic / core / data / manager / DataLayerHeartbeatSender.kt
Displaying Raw • Download
core/data/src/commonMain/kotlin/org/meshtastic/core/data/manager/DataLayerHeartbeatSender.kt 2d20cd8a4708e2ef66e98d5259f3a97ec93f240a (2d20cd8a) Text, 2.18 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.data.manager
Tff7b72import T7ee787co.touchlab.kermit.Logger
Tff7b72import T7ee787kotlinx.atomicfu.atomic
Tff7b72import T7ee787org.koin.core.annotation.Single
Tff7b72import T7ee787org.meshtastic.core.repository.PacketHandler
Tff7b72import T7ee787org.meshtastic.proto.Heartbeat
Tff7b72import T7ee787org.meshtastic.proto.ToRadio
T8b949e/**
* Centralized heartbeat sender for the data layer.
*
* Consolidates heartbeat nonce management into a single monotonically increasing counter, preventing the firmware's
* per-connection duplicate-write filter (byte-level memcmp) from silently dropping consecutive heartbeats.
*
* This is distinct from [org.meshtastic.core.network.transport.HeartbeatSender], which operates at the transport layer
* with raw byte encoding. This class works at the protobuf/data layer through [PacketHandler].
*/
Tf0883e@Single
Tff7b72class T56d364DataLayerHeartbeatSenderTb4b4b4(Tff7b72private Tff7b72val Te6edf3packetHandlerTb4b4b4: Te6edf3PacketHandlerTb4b4b4) Tb4b4b4{
Tff7b72private Tff7b72val Te6edf3nonce Tff7b72= Te6edf3atomicTb4b4b4(T79c0ff0Tb4b4b4)
T8b949e/**
* Enqueues a heartbeat with a unique nonce.
*
* @param tag descriptive label for log messages (e.g. "pre-handshake", "inter-stage")
*/
Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffTooGenericExceptionCaughtTa5d6ff"Tb4b4b4)
Tff7b72fun Td2a8ffsendHeartbeatTb4b4b4(Te6edf3tagTb4b4b4: Tffa657String Tff7b72= Ta5d6ff"Ta5d6ffhandshakeTa5d6ff"Tb4b4b4) Tb4b4b4{
Tff7b72try Tb4b4b4{
Tff7b72val Te6edf3n Tff7b72= Te6edf3nonceTb4b4b4.Te6edf3incrementAndGetTb4b4b4(Tb4b4b4)
Te6edf3packetHandlerTb4b4b4.Te6edf3sendToRadioTb4b4b4(Te6edf3ToRadioTb4b4b4(Te6edf3heartbeat Tff7b72= Te6edf3HeartbeatTb4b4b4(Te6edf3nonce Tff7b72= Te6edf3nTb4b4b4)Tb4b4b4)Tb4b4b4)
Te6edf3LoggerTb4b4b4.Te6edf3d Tb4b4b4{ Ta5d6ff"Ta5d6ff[Tffd700$Te6edf3tagTa5d6ff] Heartbeat enqueued (nonce=Tffd700$Te6edf3nTa5d6ff)Ta5d6ff" Tb4b4b4}
Tb4b4b4} Tff7b72catch Tb4b4b4(Te6edf3eTb4b4b4: Te6edf3ExceptionTb4b4b4) Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3wTb4b4b4(Te6edf3eTb4b4b4) Tb4b4b4{ Ta5d6ff"Ta5d6ff[Tffd700$Te6edf3tagTa5d6ff] Failed to enqueue heartbeat; proceedingTa5d6ff" Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Served by rngit 1.5.0 - Generated in 0.04s